package com.xiaoy.core.report.fusionchart.radarChart.entity;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class RadarChart {
	protected Chart chart=new Chart();
	protected List<Category> categories=new ArrayList<Category>();
	protected List<DataSet> dataSets=new ArrayList<DataSet>();
	
	@Override
	public String toString() {
		StringBuffer sb=new StringBuffer();
		/**
		 *  chart */
		sb.append("\t\"<chart ");
		sb.append(formap(this.chart.getAttrs()));
		sb.append(" >\" +\n \n");
		/**
		 * categories */
		if(categories.size()>0){
			sb.append("\t\t\"<categories>\"+\n");
			for(Category category:categories){
				sb.append("\t\t\t\"<category ");
				sb.append(formap(category.getAttrs()));
				sb.append(" />\"+\n");
			}
			sb.append("\t\t\"</categories>\"+\n\n");
		}
		if(dataSets.size()>0){
			for(DataSet dataset:dataSets){
				sb.append("\t\t\"<dataset ");
				sb.append(formap(dataset.getAttrs()));
				sb.append(" >\"+\n");
				for(Set set :dataset.getSets()){
					sb.append("\t\t\t\"<set ");
					sb.append(formap(set.getAttrs()));
					sb.append(" />\"+\n");
				}
				sb.append("\t\t\"</dataset>\"+\n\n");
			}
			
		}
		sb.append("\t\"</chart>\"\n");
		return sb.toString();
	}

	protected StringBuffer formap( Map<String,String> map){
		StringBuffer sb=new StringBuffer();
		Iterator<?> iterator=map.keySet().iterator();
		while(iterator.hasNext()){
			String key =iterator.next().toString();
			String value=map.get(key);
			sb.append(  key+"='"+value+"' ");
		}
		return sb;
	}

	public Chart getChart() {
		return chart;
	}
	public void setChart(Chart chart) {
		this.chart = chart;
	}
	public List<Category> getCategories() {
		return categories;
	}

	public void setCategories(List<Category> categories) {
		this.categories = categories;
	}

	public List<DataSet> getDataSets() {
		return dataSets;
	}
	public void setDataSets(List<DataSet> dataSets) {
		this.dataSets = dataSets;
	}
}
